
#include "common.h"
#include <dirent.h>

#if defined(WIN32) || defined(_WIN32)
    #ifndef WIN32_LEAN_AND_MEAN
    #define WIN32_LEAN_AND_MEAN
    #endif
    #include <windows.h>
    #include <shellapi.h>
#else
    #include <sys/stat.h>
	#include <sys/types.h>
	#include <unistd.h>
	#include <stdlib.h>
#endif
#include <sstream>

#include "luaimage.h"

using std::stringstream;


class ResManager {
    protected:
        string resroot;
        //string archivemanagerpath;
        int isInit;
        map<int,string> resloaded;
    public:
        ResManager();
        void LoadBundle(string packagepath);
        string getAbsolutePath(string relpath);
        string getRoot() { return resroot; }
        ~ResManager();
        int rmdir_recursive(string);
        int registerid(int resid,string respath) ; /**< respath is relative path */        
        int LUA_loadimage(lua_State *L) { 
        	T("LUA_loadimage")
        	if(!isInit) { E("ResManager:LUA_loadimage: isInit = FALSE")	return 0; }
        	return LUAIMAGE_load(resroot,L);
        }
#if defined(WIN32) || defined(_WIN32)
    private:
        DWORD CreateDirWithSecurity(LPCTSTR lpPath);
        int win32_process_wait(int,int);
        int win32_run_process(string );
       
        int DeleteAllFiles(string sFolder);
#endif
        
};
